package com.da.javatest.interview.session2;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

/**
 * @author chenlida
 * @date 2020/3/29 23:14
 * CyclicBarrier 相当于做加法，加到指定数字才触发
 */
public class Test13CyclicBarrier {
    public static void main(String[] args) {
        CyclicBarrier cb = new CyclicBarrier(7, () -> System.out.println("集齐七龙珠，召唤神龙\n"));

        for (int i = 0; i < 3; i++) {
            for (int j = 1; j <= 7; j++) {
                int finalI = j;
                new Thread(() -> {
                    System.out.println("第" + finalI + "个龙珠被找到");
                    try {
                        cb.await();
                    } catch (InterruptedException | BrokenBarrierException e) {
                        e.printStackTrace();
                    }
                }).start();
            }
        }


    }
}
